$OpenBSD: patch-src_mime_backend_mailcap_c,v 1.1 2011/08/03 12:51:24 edd Exp $

mailcap bug 1113: Don't leak values of duplicate fields
(related to bug 869 patch)
http://bugzilla.elinks.cz/show_bug.cgi?id=1113

--- src/mime/backend/mailcap.c.orig	Sat Aug 22 12:15:08 2009
+++ src/mime/backend/mailcap.c	Wed Aug  3 01:14:40 2011
@@ -289,7 +289,11 @@ parse_optional_fields(struct mailcap_entry *entry, uns
 			entry->copiousoutput = 1;
 
 		} else if (!c_strncasecmp(field, "test", 4)) {
-			entry->testcommand = get_mailcap_field_text(field + 4);
+			/* Don't leak memory if a corrupted mailcap
+			 * file has multiple test commands in the same
+			 * line.  */
+			mem_free_set(&entry->testcommand,
+				     get_mailcap_field_text(field + 4));
 			if (!entry->testcommand)
 				return 0;
 
@@ -301,7 +305,8 @@ parse_optional_fields(struct mailcap_entry *entry, uns
 				}
 
 		} else if (!c_strncasecmp(field, "description", 11)) {
-			entry->description = get_mailcap_field_text(field + 11);
+			mem_free_set(&entry->description,
+				     get_mailcap_field_text(field + 11));
 			if (!entry->description)
 				return 0;
 		}
